package com.example.tests;

import static com.example.fw.ContactHelper.CREATION;
import static org.testng.Assert.assertEquals;

import java.util.Collections;
import java.util.List;

import org.testng.annotations.Test;

public class GroupCompositionChangingTests extends TestBase {

	@Test
	public void addContactToGroup() {
// Create Group for Test
		// save old state for groups
		List<GroupData> oldList = app.getGroupHelper().getGroups();
		//actions
		GroupData group = new GroupData()
			.withName("group z")
			.withHeader("header z")
			.withFooter("footer z");
		app.getGroupHelper()
			.initGroupCreation()
			.fillGroupForm(group)
			.submitGroupCreation();
		// save new state
		List<GroupData> newList = app.getGroupHelper().getGroups();
		// compare states
		oldList.add(group);
		Collections.sort(oldList);
		assertEquals(newList, oldList);

// Create Contact for Test
		// save old state
		List<ContactData> oldContactList = app.getContactHelper().getContacts();
		//actions
		app.navigateTo().addNewContactPage();
		ContactData contact = new ContactData()
			.withFirstName("First name Z")
			.withLastName("Last name Z");
		app.getContactHelper()
			.fillContactForm(contact, CREATION)
			.submitContactCreation()
			.returnToMainPage();
		// save new state
		List<ContactData> newContactList = app.getContactHelper().getContacts();
		//compare states
		oldContactList.add(contact);
		Collections.sort(oldContactList);
		Collections.sort(newContactList);
		assertEquals(newContactList, oldContactList);
		
// Add created Contact to the Group
		app.getContactHelper()
			.selectContactZ()
			.addingContactToGroup()
			.returnToContactListForGroup();
		app.navigateTo().mainPageByPic();
		}
	
	@Test
	public void removeContactFromGroup() {
		app.navigateTo().mainPage();
		app.getContactHelper()
			.openContactsListForGroup()
			.selectContactZ()
			.submitRemovingContactFromGroup()
			.returnToContactListForGroup();
		app.navigateTo().mainPageByPic();
		}

}